<template>
  <div class>
    <el-card style="position:relative;">
      <el-form :model="searchForm" label-width="80px">
        <el-row>
          <el-col :span="5">
            <el-form-item label="资料编号" size="small">
              <el-input v-model="searchForm.mateCode" placeholder="请输入企业名称"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="资料名称" size="small">
              <el-input v-model="searchForm.mateName" placeholder="请输入企业名称"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="资料类型" size="small">
              <el-select v-model="searchForm.mateType" placeholder="请选择项目来源" style="width: 100%;">
                <el-option label="请选择" value=""></el-option>
                <el-option label="基础材料" value="1"></el-option>
                <el-option label="反担保物材料" value="2"></el-option>
                <el-option label="法律文书" value="3"></el-option>
                <el-option label="保后材料" value="4"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="资料类别" size="small">
              <el-select v-model="searchForm.mateCategory" placeholder="请选择资料类别" style="width: 100%;">
                <el-option label="请选择" value=""></el-option>
                <el-option label="企业材料" value="1"></el-option>
                <el-option label="相关报告" value="2"></el-option>
                <el-option label="个人反担保" value="3"></el-option>
                <el-option label="企业反担保" value="4"></el-option>
                <el-option label="抵质押物" value="5"></el-option>
                <el-option label="合同" value="6"></el-option>
                <el-option label="保后报告" value="7"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="2">
            <el-button type="primary" size="small" style="margin-left:5px" icon="el-icon-search" @click="init">查询</el-button>
          </el-col>
          <el-col :span="2">
            <el-button type="success" size="small" icon="el-icon-circle-plus-outline" @click="add">新增</el-button>
          </el-col>
        </el-row>
      </el-form>
    </el-card>

    <el-table :data="tableData" border style="width: 100%" size="mini">
      <el-table-column type="index" label="序号" align="center" width="50">
      </el-table-column>
      <el-table-column prop="mateType" label="资料类型" align="center" width="160" :formatter="mateTypeFor">
      </el-table-column>
      <el-table-column prop="mateCode" label="资料编号" align="center" width="120">
      </el-table-column>
      <el-table-column prop="mateName" label="资料名称" align="center">
      </el-table-column>
      <el-table-column prop="isUse" align="center" label="是否采用" width="120" :formatter="isUseFor">
      </el-table-column>
      <el-table-column label="操作" align="center" width="100">
        <template slot-scope="scope">
          <el-button @click="toEdit(scope.row)" type="text" size="small">编辑</el-button>
          <el-button @click="toDel(scope.row)" type="text" size="small" style="color: red;">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-card style="text-align:right;">
      <el-pagination @size-change="sizeChange" @current-change="currentChange" :current-page="currentPage" :page-sizes="[ 10, 20,30, 40]" :page-size="pageSize" background layout="total, sizes, prev, pager, next" :total="total"></el-pagination>
    </el-card>

    <!-- --------------------------------------------弹出框 -->
    <el-dialog title="新增资料" :visible.sync="dialogVisible1" width="50%" :before-close="handleClose">
      <insert></insert>
    </el-dialog>

    <el-dialog title="编辑资料" :visible.sync="dialogVisible2" width="50%" :before-close="handleClose">
      <update ref="update"></update>
    </el-dialog>
  </div>
</template>

<script>
import insert from "./component/mate-list-insert";
import update from "./component/mate-list-update";
export default {
  components: { insert, update },
  data() {
    return {
      total: 0,
      pageSize: 10,
      currentPage: 1,
      tableData: [],
      searchForm: {
        mateCode: "",
        mateName: "",
        mateType: "",
        mateCategory: ""
      },
      dialogVisible1: false,
      dialogVisible2: false,
      formData: {}
    };
  },
  computed: {},
  mounted() {
    this.init();
  },
  methods: {
    //表格翻译
    isUseFor: function(row, column) {
      return row.isUse == "0" ? "否" : row.isUse == "1" ? "是" : "其他";
    },
    //table翻译 资料类型
    mateTypeFor(row, column) {
      if (row.mateType === "1") {
        return "基础材料";
      } else if (row.mateType === "2") {
        return "反担保物材料";
      } else if (row.mateType === "3") {
        return "法律文书";
      } else {
        return "保后材料";
      }
    },

    toEdit(row) {
      this.formData = row;
      this.dialogVisible2 = true;
      this.$nextTick(() => {
        this.$refs.update.csh(row);
      });
    },
    sizeChange(n) {
      this.pageSize = n;
      this.init();
    },
    currentChange(n) {
      this.currentPage = n;
      this.init();
    },
    init() {
      let params = {
        pageNum: this.currentPage,
        pageSize: this.pageSize,
        mateCode: this.searchForm.mateCode,
        mateName: this.searchForm.mateName,
        mateType: this.searchForm.mateType,
        mateCategory: this.searchForm.mateCategory
      };
      this.$api
        .formPost("/api/biz/baseMaterial/doGetList", params)
        .then(res => {
          if (res.retHead.code === "0000000") {
            this.tableData = res.retBody.list;
            this.total = res.retBody.total;
          }
        });
    },
    add() {
      this.dialogVisible1 = true;
    },
    handleClose() {
      this.dialogVisible1 = false;
      this.dialogVisible2 = false;
    },
    del(row) {
      this.$api
        .formPost("/api/biz/baseMaterial/doRmById", {
          id: row.id,
          mateRefId: row.mateRefId
        })
        .then(res => {
          if (res.retHead.code === "0000000") {
            this.tableData = res.retBody.list;
            this.$message({
              type: "info",
              message: "删除成功"
            });
            this.init();
          } else {
            this.$message({
              type: "info",
              message: res.retHead.message
            });
          }
        });
    },
    toDel(row) {
      let that = this;
      this.$confirm("确定删除?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          that.del(row);
        })
        .catch(() => {});
    }
  },
  created() {}
};
</script>
<style lang='scss' scoped>
.btns {
  text-align: right;
}
.icon-arrow {
  position: absolute;
  bottom: 5px;
  left: 0;
  width: 100%;
  height: 1px;
  background-color: #f1f1f1;
  i {
    background-color: #fff;
    position: absolute;
    color: #999;
    bottom: -7px;
    margin-left: 50%;
    transform: translateX(-50%);
    cursor: pointer;
  }
}
</style>